<?php
namespace app\index\model;
use think\Model;
use think\Db;
class Operation extends Model
{
    public function put_notice($content, $worker){
        $res = Db::table("laytp_notice")
            ->insert(array(
                "notice" => $content,
                "worker" => $worker,
            ));
        return $res;
    }

    public function get_channel($code=null){
        if($code != null){
            $map["code"] = $code;
        }else{
            $map = "1=1";//where true
        }
        $channel = Db::name('laytp_channel')
            ->field('
                id as id,
                name as name, 
                code as code,
                status as status
            ')
            ->where($map)
            ->select();
        if($channel){
            return array("status"=>1, "data"=>$channel);
        }else{
            return array("status"=>0, "data"=>[]);
        }
    }

    public function change_channel($channel, $status){
        if($channel == "channel"){
            $map = "1=1";
        }else{
            $map["code"] = $channel;
        }
        $res = Db::table("laytp_channel")
            ->where($map)
            ->update(array(
                "status" => $status,
            ));
        return $res;
    }
}